package com.konsung.ksdc.manager.shop;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.konsung.ksdc.R;
import com.konsung.ksdc.bean.netbean.OrderProductNetBean;
import com.konsung.ksdc.common.utils.StringUtils;
import com.konsung.ksdc.config.MyApplication;
import com.squareup.picasso.Picasso;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 评价详情列表适配器
 * Created by DJH on 2017/3/3 0003.
 */

public class EvaluateDetailAdapter extends BaseAdapter {

    private List<OrderProductNetBean> productBeanList;

    /**
     * 构造方法
     * @param list 订单商品列表集合
     */
    public EvaluateDetailAdapter(List<OrderProductNetBean> list) {
        productBeanList = list;
    }

    @Override
    public int getCount() {
        if (productBeanList != null) {
            return productBeanList.size();
        }
        return 0;
    }

    @Override
    public Object getItem(int position) {
        return productBeanList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder = null;

        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(MyApplication.getContext())
                    .inflate(R.layout.list_for_evaluate_detail, null);
            ButterKnife.bind(holder, convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        final OrderProductNetBean bean = productBeanList.get(position);
        String iconImageUrl = bean.getProductIconPath();
        Picasso.with(MyApplication.getContext())
                .load(StringUtils.appendPicPath(iconImageUrl))
                .placeholder(R.drawable.pic_talkbox_sel)
                .error(R.drawable.pic_talkbox_sel)
                .into(holder.ivProduct);
        holder.tvEvaluate.setText(bean.getEvaluateTitle());
        return convertView;
    }

    /**
     * 适配器
     */
    static class ViewHolder {
        @Bind(R.id.iv_product)
        ImageView ivProduct;
        @Bind(R.id.tv_evaluate)
        TextView tvEvaluate;
    }
}
